package com.tinyengine.it.common.utils;

import com.tinyengine.it.common.enums.ApiReqMethod;

public class GenUtils {

    public static String lowerFirst(String str) {
        if (str == null || str.isEmpty()) {
            return str;
        }
        return str.substring(0, 1).toLowerCase() + str.substring(1);
    }

    public static String upperFirst(String str) {
        if (str == null || str.isEmpty()) {
            return str;
        }
        return str.substring(0, 1).toUpperCase() + str.substring(1);
    }

    public static String getMappingAnnotation(String method) {
        if (method == null || method.isEmpty()) {
            return "Invalid Method";
        }
        ApiReqMethod httpMethod = ApiReqMethod.valueOf(method.toUpperCase());

        switch (httpMethod) {
            case GET:
                return "GetMapping";
            case POST:
                return "PostMapping";
            default:
                return method + "UnsupportedMethod";
        }
    }

    public static String getImportInfo(String schemaType) {

        String imports = "java.lang.*";

        switch (schemaType.toUpperCase()) {
            case "BYTE":
                imports = "java.lang.Byte";
                break;
            case "SHORT":
                imports = "java.lang.Short";
                break;
            case "INTEGER":
                imports = "java.lang.Integer";
                break;
            case "LONG":
                imports = "java.lang.Long";
                break;
            case "FLOAT":
                imports = "java.lang.Float";
                break;
            case "DOUBLE":
                imports = "java.lang.Double";
                break;
            case "BOOLEAN":
                imports = "java.lang.Boolean";
                break;

            // 时间相关
            case "LOCALDATE":
                imports = "java.time.LocalDate";
                break;
            case "LOCALTIME":
                imports = "java.time.LocalTime";
                break;
            case "LOCALDATETIME":
            case "DATE":
                imports = "java.time.LocalDateTime";
                break;
            case "ZONEDDATETIME":
                imports = "java.time.ZonedDateTime";
                break;
            case "INSTANT":
                imports = "java.time.Instant";
                break;
            case "FILE":
                imports = "org.springframework.web.multipart.MultipartFile";
                break;
        }
        return imports;
    }

    public static String slashTurningPoint(String str) {
        return str.replaceAll("[/\\\\]+", ".");
    }

}
